const { where } = require('sequelize')
const Addr = require('../model/addr.model')
class AddrService {
    async createAddr(addr) {
        return await Addr.create(addr)
    }
    async findAllAddr(id) {
        const user_id = id
        const res = await Addr.findAll({
            where: {
                user_id
            }
        })
        return res
    }
    async updateAddr(id, addr) {
        return await Addr.update(addr, {
            where: {
                id
            }
        })
    }
    async removeAddr(id) {
        return await Addr.destroy({
            where: {
                id
            }
        })
    }
    async setDefaultAddr(id) {
        await Addr.update({
            is_default: false
        }, { where: {} })
        return await Addr.update({
            is_default: true
        }, {
            where: {
                id
            }
        })
    }
}

module.exports = new AddrService()